<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>

<div class="span9">

    <h2><?php echo $titulo; ?></h2>
    <h4><?php echo $subtitulo; ?></h4>    
    <?php if (!empty($reporte)) { ?>

        <p><a target="_blank" href="<?php echo base_url($url . $parametro . '/1'); ?>" class="btn hidden_pdf">Pdf</a></p>

        <div class="container-table">
            <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-hover table-bordered">
                <thead>
                    <?php echo (isset($pretitulo)) ? $pretitulo : ''; ?> 
                    <tr>
                        <?php foreach ($titulos as $titulo) { ?>
                            <th><?php echo $titulo; ?></th>
                        <?php } ?>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $color = 'odd';
                    foreach ($reporte as $dato) {
                        $color = ( $color == 'odd') ? 'even' : 'odd';
                        ?>
                        <tr class="<?php echo $color; ?>">
                            <?php foreach ($atributos as $atributo) { ?>
                                <?php if (strpos($atributo,'fecha') === FALSE) { ?>
                                    <td><?php echo $dato->$atributo; ?></td>
                                <?php } else { ?>
                                    <td><?php echo database_to_normal_date($dato->$atributo); ?></td>
                                <?php } ?>
                            <?php } ?>
                        </tr>
                        <?php
                    }
                    ?>  
                </tbody>
            </table>
        </div> 
    <?php } ?>

    <?php if (isset($grafico)) { ?>
        <?php
        foreach ($grafico as $gr) {
            if ($gr['tipo'] == 'torta') {
                $chd = '';
                foreach ($gr['datos'] as $dato) {
                    $chd .= $dato['porcentaje'] . ',';
                    $chl .= $dato['etiqueta'] . '|';
                }
                $chtt = $gr['titulo'];
                $chd = substr($chd, 0, -1);
                $chl = substr($chl, 0, -1);

                $source = 'http://chart.googleapis.com/chart?cht=p&chs=650x300&chd=t:' . urlencode($chd) . '&chl=' . urlencode($chl) . '&chtt=' . urlencode($chtt);
                $rand = rand(0, 9999);
                $dest = PATH_UPLOAD . "graficos/grafico-$rand.jpg";
                copy($source, $dest);
                ?>
                <img src="<?php echo base_url($dest); ?>" alt="" />    
            <?php } ?>   
        <?php } ?>
    <?php } ?>
</div>

